Skip to content

First run at 500 error handling in fetch_resource#47

Open
kshepherd wants to merge 1 commit intothe-library-code:mainfrom
kshepherd:error_bandaid
Open

First run at 500 error handling in fetch_resource#47
kshepherd wants to merge 1 commit intothe-library-code:mainfrom
kshepherd:error_bandaid

Conversation

@kshepherd
Copy link
Collaborator

This isn't intended as a proper solution for #46 but it's an example of what I'm suggesting initially as a better way to handle 500s (and I added 405s as they were easier for me to test)

Since the higher level "get this, search that" client methods don't put fetch_resource in a try block (typically that is done when trying to parse the actual JSON response), the new exception should be thrown all the way back to the calling script so it can be handled appropriately by end developers.

e.g.

# Forcing a 405 error to test (500 errors are handled too but are a bit harder to 'force' in a working system!)
try:
    r = d.fetch_resource(f"{d.API_ENDPOINT}/config/properties")
    print(r.status_code)
except DSpaceServerError as e:
    # Here you can see the formatted error message
    print("Here is a nice formatted error message:")
    print(e.format_message())
    # Here you can see a pretty print of the exception as dict, with the properties you can read
    print("\nHere is the exception as a dict:")
    pprint(e.__dict__)

@kshepherd kshepherd self-assigned this Jan 30, 2025
@kshepherd kshepherd added the breaking change This PR introduces breaking changes and would require a new major release label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This PR introduces breaking changes and would require a new major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant